<%@ page import="com.interfaces.*" %>
<%@ page import="com.core.guarantee.pojo.Guarantee" %>
<%@ page import="com.core.guarantee.GuaranteeJspKeys" %>
<%@ page import="com.core.sysDict.SysDictJsp" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html>
<!--
This is a starter template page. Use this page to start your new project from
scratch. This page gets rid of all links and provides the needed markup only.
-->
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>修改招保信息</title>
    <!-- Tell the browser to be responsive to screen width -->
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">

    <%
    	String path = request.getContextPath();
                    path = "/".equals(path)?"":path;
                    request.setAttribute("path", path);
                    String sysDictJson=SysDictJsp.getSysDictJson(session);
    %>
    <script type="text/javascript">
        var path = "${path}";
    </script>

    <!-- Bootstrap 3.3.6 -->
    <link rel="stylesheet" href="${path}/public/adminlte/bootstrap/css/bootstrap.min.css">
    <!-- Font Awesome -->
    <link rel="stylesheet" href="${path}/public/font-awesome-4.7.0/css/font-awesome.min.css">
    <!-- Ionicons -->
    <link rel="stylesheet" href="${path}/public/ionicons/ionicons.min.css">
    <!-- Select2 -->
  	<link rel="stylesheet" href="${path}/public/adminlte/plugins/select2/select2.min.css"> 
    <!-- DataTables -->
    <link rel="stylesheet" href="${path}/public/adminlte/plugins/datatables/dataTables.bootstrap.css">
    <!-- Theme style -->
    <link rel="stylesheet" href="${path}/public/adminlte/dist/css/AdminLTE.min.css">
    <!-- AdminLTE Skins. We have chosen the skin-blue for this starter
          page. However, you can choose any other skin. Make sure you
          apply the skin class to the body tag so the changes take effect.
    -->
    <link rel="stylesheet" href="${path}/public/adminlte/dist/css/skins/_all-skins.min.css">

    <link rel="stylesheet" href="${path}/css/common.css">

    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
    <script type="text/javascript" src="${path}/js/json2.js"></script>
</head>
<!--
BODY TAG OPTIONS:
=================
Apply one or more of the following classes to get the
desired effect
|---------------------------------------------------------|
| SKINS         | skin-blue                               |
|               | skin-black                              |
|               | skin-purple                             |
|               | skin-yellow                             |
|               | skin-red                                |
|               | skin-green                              |
|---------------------------------------------------------|
|LAYOUT OPTIONS | fixed                                   |
|               | layout-boxed                            |
|               | layout-top-nav                          |
|               | sidebar-collapse                        |
|               | sidebar-mini                            |
|---------------------------------------------------------|
-->
<body >
<%
	Guarantee guarantee = (Guarantee) request.getAttribute(GuaranteeJspKeys.JspParam_Guarantee);
%>

<div class="container">
            <div class="row">
            	<div class="col-md-4">
                    <div class="form-group">
                        <label for="state">当前招保状态</label>
                        <select readonly="readonly" class="form-control" id="state" value="${guarantee.state}"></select>
                    </div>
                </div>
                 <div class="col-md-4">
                    <div class="form-group">
                        <label for="firstPersonName">1号人姓名</label>
                        <input type="text" class="form-control" id="firstPersonName" value="${guarantee.firstPersonName}">
                    </div>
                </div>
                <div class="col-md-4">
                    <div class="form-group">
                        <label for="pinyinName">姓名拼音</label>
                        <input type="text" class="form-control" id="pinyinName"value="${guarantee.pinyinName}">
                    </div>
                </div>
            </div>
            <div class="row">
            	<div class="col-md-4">
                    <div class="form-group">
                        <label for="incomingDate">入境日期</label>
                        <input type="text" class="form-control" id="incomingDate"value="${guarantee.incomingDate}">
                    </div>
                </div>
                 <div class="col-md-4">
                    <div class="form-group">
                        <label for="leaveDate">出境日期</label>
                        <input type="text" class="form-control" id="leaveDate"value="${guarantee.leaveDate}">
                    </div>
                </div>
                <div class="col-md-4">
                    <div class="form-group">
                        <label for="visaType">签证类型</label>
                        <select class="form-control" id="visaType" value="${guarantee.visaType}"></select>
                    </div>
                </div>
                <div class="col-md-4">
                    <div class="form-group">
                        <label for="sendAgentId">送签社</label>
							<select class="form-control select2" id="sendAgentId">
                        	</select>
                    </div>
                </div>
                <div class="col-md-4">
                    <div class="form-group">
                        <label for="txtnumber">其余人数</label>
                        <input type="text" class="form-control" id="txtnumber"value="${guarantee.number}">
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="col-md-4">
                    <div class="form-group"id="isStateNorthCountry1">
                        <label for="isStateNorthCountry">要在冲绳和东北六省哪里住</label>
                        <select   class="form-control" id="isStateNorthCountry" value="${guarantee.isStateNorthCountry}">
                        </select>
                    </div>
                </div>
                <div class="col-md-4">
                    <div class="form-group" id="isPastCome1">
                        <label for="isPastCome">过去是否来过</label>
                        <select class="form-control" id="isPastCome" value="${guarantee.isPastCome}">
                        	<option value="#">==请选择==</option>
                       		<option value="0"<%if("0".equals(guarantee.getIsPastCome())){%>selected = "selected"<%}%>>否</option>
                       		<option value="1"<%if("1".equals(guarantee.getIsPastCome())){%>selected = "selected"<%}%>>是</option>
                        </select>
                    </div>
                </div>
                <div class="col-md-4">
                    <div class="form-group" id="pastCameRecord1">
                        <label for="pastCameRecord" id="pastCameRecord1">过去访问过城市的记录</label>
                        <select   class="form-control" id="pastCameRecord" value="${guarantee.pastCameRecord}">
                        </select>
                    </div>
                </div>
            </div>
            <div class="row">
            	
            	<div class="col-md-4">
                    <div class="form-group" id="txtGuaranteeId1">
                        <label for="txtGuaranteeId">招保代码</label>
                        <input type="text" class="form-control" id="txtGuaranteeId" readonly="readonly" value="${guarantee.id}">
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="col-md-12">
                    <button type="submit" class="btn btn-primary" id="btnUpdate1">保 存</button>
				    <button class="btn btn-primary" onclick="btnUpdateState(1)">提 交</button>
				    <button class="btn btn-primary" onclick="btnUpdateState(0)">取消提交</button>
				    <button class="btn btn-primary" onclick="btnUpdateState(4)">退回修改</button>
				    <button class="btn btn-primary" onclick="btnUpdateState(2)">撤 回</button>
				    <button class="btn btn-primary" onclick="btnUpdateDel()">删 除</button>
                </div>
            </div>
<!-- ./wrapper -->
</div>
<!-- REQUIRED JS SCRIPTS -->

<!-- jQuery 2.2.3 -->
<script src="${path}/public/adminlte/plugins/jQuery/jquery-2.2.3.min.js"></script>
<!-- Bootstrap 3.3.6 -->
<script src="${path}/public/adminlte/bootstrap/js/bootstrap.min.js"></script>
<!-- DataTables -->
<script src="${path}/public/adminlte/plugins/datatables/jquery.dataTables.min.js"></script>
<script src="${path}/public/adminlte/plugins/datatables/dataTables.bootstrap.min.js"></script>
<!-- Select2 -->
<script src="${path}/public/adminlte/plugins/select2/select2.full.min.js"></script>
<!-- SlimScroll -->
<script src="${path}/public/adminlte/plugins/slimScroll/jquery.slimscroll.min.js"></script>
<!-- FastClick -->
<script src="${path}/public/adminlte/plugins/fastclick/fastclick.js"></script>
<!-- AdminLTE App -->
<script src="${path}/public/adminlte/dist/js/app.min.js"></script>
<script src="${path}/js/sysDict.js"></script>
<!-- bootstrap datepicker -->
<script src="${path}/public/adminlte/plugins/datepicker/bootstrap-datepicker.js"></script>
<script src="${path}/js/PYtranslate.js"></script>
<!-- Optionally, you can add Slimscroll and FastClick plugins.
     Both of these plugins are recommended to enhance the
     user experience. Slimscroll is required when using the
     fixed layout. -->
<!-- page script -->
<script>
$(document).ready(function() {
	$("#state").attr("disabled","disabled");
	function selectOption(key_no,key_value,re,flag){
	var tempoption=new Array();
	if(flag==0){
		tempoption.push({label:'==请选择==',value:"#"})
	}else if(flag==1){
		//此处选择无赋值，是因为后台会判定该值是否为null或空，若是，不作为查询条件添加到查询sql中
		tempoption.push({label:'全部',value:""})
	}
	$.each(re.data,function(i,n){
		if(n.key_no==key_no){
			if(n.key_value!='#'){
				tempoption.push({label:n.key_caption,value:n.key_value})
			}
		}
	});
	return tempoption;
	}
	var sysDict1='<%=sysDictJson%>';
	var re1 = JSON.parse(sysDict1);
	var temOption=selectOption('1001',null,re1,0);
	var temPlaceOfPass=selectOption('1003',null,re1,0);
	var visaInfoId1=$("#txtVisaInfoId").val();
	console.info(visaInfoId1);
    $(".nameCreate").change(function(){
  		console.info(".nameCreate");
	});
	});
	
	
	
function btnUpdateState(code) {
       	var show="";
       	if(code==1){
       		show="确定提交所选项目?"
       	}else if(code==0){
       		show="确定取消提交所选项目?"
       	}else if(code==2){
       		show="确定回退所选项目?"
       	}else if(code==4){
       		show="确定退回并修改所选项目?"
       	}
       	if(confirm(show)){
       	 var visaInfoId =$("#txtGuaranteeId").val(); 
       	 var nowState =$("#state").val(); 
       	 	if(code==1){
       			if(nowState==1||nowState==3){
       				alert("当前的签证状态不允许这次操作!!");
       				return false;
       			}
       		}else if(code==0){
       			if(nowState!=1){
       				alert("当前的签证状态不允许这次操作!!");
       				return false;
       			}
       		}else if(code==2){
       			if(nowState!=3){
       				alert("当前的签证状态不允许这次操作!!");
       				return false;
       			}
       		}else if(code==4){
       			if(nowState!=3){
       				alert("当前的签证状态不允许这次操作!!");
       				return false;
       			}
       		}
       		$.ajax({  
                   type:"POST",  
                   url:"${path}<%=GuaranteeController.URL_UPDATESTATE%>",  
                   data:{"delitems":visaInfoId,"afterState":code},    
                   success:function(result){ 
                   		var re=JSON.parse(result);
                   		console.info (result);
                   		console.info (result.returnCode);
                   	   if(re.returnCode=="0"){
                       		var url= window.location.search;
                			var arr = url.split('&');
                			console.info(arr);
                			var CustodianID2=new Date().getTime()+''+Math.floor(Math.random() * 8998 + 1000);
                			parent.refresh(arr[arr.length-1]);
                			parent.refresh2(arr[arr.length-2]);
                   	   }else{
                   	   	alert(re.msg);
                   	   }
                   },  
           		   error:function(request) {      // 设置表单提交出错
                	alert(request);  //登录错误提示信息
            	   }
               });  
       	}
       } 
       
function btnUpdateDel () {
               //判断至少写了一项  
               if(confirm("确定删除所选项目?")){  
               var visaInfoId =$("#txtGuaranteeId").val();
               console.info(visaInfoId);  
               var nowState =$("#state").val(); 
               if(nowState!=0){alert("该签证状态不能删除!只有未提交状态才能进行删除!!");return false}
               console.info(visaInfoId+"按钮类id");
               $.ajax({  
                   type:"POST",  
                   url:"${path}<%=VisaApplicationInfoController.URL_DELETE%>",  
                   data:{"delitems":visaInfoId},    
                   success:function(result){ 
                   		var re=JSON.parse(result);
                   		console.info (result);
                   		console.info (result.returnCode);
                   	   if(re.returnCode=="0"){
                       		var url= window.location.search;
                			var arr = url.split('&');
                			console.info(arr);
                			var CustodianID2=new Date().getTime()+''+Math.floor(Math.random() * 8998 + 1000);
                			parent.refresh(arr[arr.length-1]);
                			parent.closeAndActiveTab(arr[arr.length-2],arr[arr.length-1]);
                   	   }else{
                   	   	alert(re.msg);
                   	   }
                   },  
           		   error:function(request) {      // 设置表单提交出错
                	alert(request);  //登录错误提示信息
            	   }
               });  
               }  
       }; 
       	
$(function () {
	var getName="";
	$.ajax({
		type: "POST",
		url: "${path}<%=SendAgentController.URL_NAME%>",
		data: {id:"<%=guarantee.getSendAgentId()%>"},
		async:false,
		success:function(data){
		getName=data;
		}
	});
	var getName2=getName.replace(new RegExp("\"","gm"),"");
	console.info(typeof(getName));
	console.info(getName.replace("\"",""));
	function outputObj(repo) { var description = ""; for (var i in repo) { description += i + " = " + repo[i] + "\n"; } console.info(description); }
	function formatRepo (repo) {
	  outputObj(repo);
      if (repo.loading) {return repo.text;}
      return repo.text+"("+repo.id+")";
    }

    function formatRepoSelection (repo) {
    return repo.text; 
    }
	var sysDict='<%=sysDictJson%>';
	var re = JSON.parse(sysDict);
	getSelect($("#visaType"),'1002',<%=guarantee.getVisaType()%>,re,0);
	getSelect($("#state"),'1001',<%=guarantee.getState()%>,re,0);
	getSelect($("#isStateNorthCountry"),'1004',"<%=guarantee.getIsStateNorthCountry()%>",re,0);
	getSelect($("#pastCameRecord"),'1005',"<%=guarantee.getPastCameRecord()%>",re,0);
	if($("#visaType").val()=="#"||$("#visaType").val()==0||$("#visaType").val()==1||$("#visaType").val()==2){
			$("#isStateNorthCountry1").hide();
			$("#isPastCome1").hide();
			$("#pastCameRecord1").hide();
	}
	if($("#isPastCome").val()=="#"||$("#isPastCome").val()==0){
	$("#pastCameRecord1").hide();
	}
	$("#visaType").change(function(){
		if($(this).val()=="#"||$(this).val()==0||$(this).val()==1||$(this).val()==2){
			$("#isStateNorthCountry1").hide();
			$("#isPastCome1").hide();
			$("#pastCameRecord1").hide();
		}else if($(this).val()==3){
			$("#isStateNorthCountry1").show();
			$("#isPastCome1").show();
			if($(isPastCome).val()=="1"){
				$("#pastCameRecord1").show();
			}
		}
	})
	$("#isPastCome").change(function(){
		if($(this).val()=="0"||"#"==$("#isPastCome").val()){
			$("#pastCameRecord1").hide();
		}else if($(this).val()=="1"){
			$("#pastCameRecord1").show();
		}
	})
	$("#sendAgentId").select2({
	language: "zh-CN",
	width: "100%",
  	ajax: {
        url: "${path}<%=TravelAgentController.URL_SEARCHSENDAGENT%>",
        dataType: 'json',
        delay: 1000,
        type:"post",
        data: function (params) {
        params.page = params.page || 1;
          return {
            sendAgentCode: params.term, // 关键字
            curPage: params.page, 
            pageSize: 10,
	        singlePage: 0          
          };
        },
        processResults: function (data, params) {
          params.page = params.page || 1;
          return {
            results: data.items,//items:数据 data.total_count:总记录数,items中，字段id为option中的value值，
            pagination: {
              more: (params.page * 10) < data.total_count //页数*每页记录数小于总记录数时，可记录下拉
            }
          };
        },
        cache: true
      },
      escapeMarkup: function (markup) { return markup; },
      minimumInputLength: 0,
      templateResult: formatRepo,
      templateSelection: formatRepoSelection
	});
	var testss=<%=guarantee.getSendAgentId()%>;
	console.info(testss);
	$("#sendAgentId").append('<option value="<%=guarantee.getSendAgentId()%>">'+getName2+"</option>");
	$('#incomingDate').datepicker({
	  format: 'yyyy-mm-dd',
      autoclose: true
    });
    $('#leaveDate').datepicker({
	  format: 'yyyy-mm-dd',
      autoclose: true
    });
    $('#addDate').datepicker({
	  format: 'yyyy-mm-dd',
      autoclose: true
    });
	$('#txtGuaranteeId1').hide();
	
	$('#firstPersonName').on("input",function() { 
	var temp =$("#firstPersonName").val();
	var res=ConvertPinyin(temp); 
   	$('#pinyinName').val(res);  
	});       
    $("#btnUpdate1").click(function () {
        var guaranteeId =$("#txtGuaranteeId").val();
        var firstPersonName = $("#firstPersonName").val();
        if(firstPersonName == ""){
            alert("请输入1号人姓名");
            return;
        }
        var pinyinName = $("#pinyinName").val();
        if(pinyinName == ""){
            alert("请输入1号人姓名拼音");
            return;
        }
        var txtnumber = $("#txtnumber").val();
        if(txtnumber == ""){
            alert("请输入人数");
            return;
        }
        var incomingDate = $("#incomingDate").val();
        if(incomingDate == ""){
            alert("请输入入境日期");
            return;
        }
        var leaveDate = $("#leaveDate").val();
        if(leaveDate == "#"){
            alert("请输入出境日期");
            return;
        }else if(leaveDate<incomingDate){
        	alert("出境日期不能早于入境日期!!");
        	return;
        } 
        var visaType = $("#visaType").val();
        if(visaType == "#"||visaType =="" ){
            alert("请输入签证类型");
            return;
        }
        var sendAgentId = $("#sendAgentId").val();
        if(sendAgentId == ""||sendAgentId==null){
            alert("请输入送签社");
            return;
        }  
        var isStateNorthCountry2= $("#isStateNorthCountry").val();
        if(visaType=="#"||visaType=="0"||visaType=="1"||visaType=="2"){isStateNorthCountry2="#";}  
        var isPastCome2= $("#isPastCome").val();
        if(visaType=="#"||visaType=="0"||visaType=="1"||visaType=="2"){isPastCome2="#";}  
        var pastCameRecord2= $("#pastCameRecord").val();
        if(isPastCome2=="#"){pastCameRecord2="#"}   
        $.ajax({
            url:"${path}<%=GuaranteeController.URL_UPDATE%>",
            type:"post",
            data:{
                id:guaranteeId,
                firstPersonName:firstPersonName,
                pinyinName:pinyinName,
                number:txtnumber,
                incomingDate:incomingDate,
				leaveDate:leaveDate,
				visaType:visaType,
				sendAgentId:sendAgentId,
				isStateNorthCountry:isStateNorthCountry2,
				isPastCome:isPastCome2,
				pastCameRecord:pastCameRecord2
            },
            success:function(result){
                
                if(result.returnCode=="0"){
                	alert("修改招保信息成功！");
                	var url= window.location.search;
                	var arr = url.split('&');
                	var CustodianID2=new Date().getTime()+''+Math.floor(Math.random() * 8998 + 1000);
                	parent.refresh(arr[arr.length-1]);
                }else{
                    alert(result.msg);
                }
            },
            error:function(request) {      // 设置表单提交出错
                alert(request);  //登录错误提示信息
            }
        });

        return false;
     });
     });
      function freshOK(){
        console.info("success");
        location.reload();
        }; 
</script>
</body>
</html>
 